package com.travel.Service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.travel.Bean.Strategy;
import com.travel.Bean.User_up;
import com.travel.JPA.StrategyJPA;
import com.travel.JPA.User_upJPA;
import org.bytedeco.opencv.presets.opencv_core;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class User_upServiceImpl {

    @Autowired
    private User_upJPA user_upJPA;
    @Autowired
    private StrategyJPA strategyJPA;

    /**
     * 是否已点赞该攻略
     *
     * @param userId     用户id
     * @param strategyId 攻略id
     * @return boolean
     */
//    @CacheEvict(value = "Travel_userUp",key = "(#userId)('_')(#strategyId)")
    public boolean strategy_up_YN(String userId,Integer strategyId){
        return user_upJPA.findUidSidYN(userId,strategyId)>0;
    }

    /**
     * 找到用户用户id
     *
     * @param userId 用户id
     * @param page   页面
     * @param limit  记录条数
     * @return {@link PageInfo}<{@link Strategy}>
     */
    public PageInfo<Strategy> findUser_upByUserId(String userId,Integer page,Integer limit){
        PageHelper.startPage(page,limit);
        List<Integer> strategyIds = user_upJPA.findByUserid(userId);
        List<Strategy> strategies = strategyJPA.findAllByIds(strategyIds);
        return new PageInfo<>(strategies);
    }






}
